﻿//---------------------------------------------------------------------
// Function called on document ready
//---------------------------------------------------------------------
 $(function() {
 	setTimeout("Documents_GenerateJFileTree()", 0);
 	setTimeout("Documents_InitDmsGrid()", 0);
 	//Popup panels
 	$("#PanelCreateFolder").dialog({  position: 'top' , autoOpen: false, modal: true, width: 500,height:100, title: 'Create Folder' });
 	//$("#phUploadSeperator").grouptitle({ classname: "vm-frm-title-blue", title: "" });
    $("#btnCreateFolder").click(function() { $("#PanelCreateFolder").dialog("open"); });
 	//$("#dvRegistrationForm").dialog("open")
 });
//---------------------------------------------------------------------
// 
//---------------------------------------------------------------------
function Documents_InitDmsGrid() {
    $(".dmsGrid").flexigrid({
        dataType: 'json',
        colModel: [
           
            { display: 'Name', name: 'Name', width: 250, sortable: true, align: 'left', process: function(celDiv, id) {$(celDiv).css("text-align","left");} },
        	{ display: 'Category', name: 'Category', width: 200, align: 'center' },
        	{ display: 'Date created', name: 'Date_modified', width: 100, align: 'center' },
        	{ display: 'Size', name: 'Size', width: 75, align: 'center'},
        	{ display: 'Owner', name: 'Owner', width: 250, align: 'center' },
        	{ display: 'Permissions', name: 'Permissions', width: 75, align: 'center' }
            ],
        sortname: "Title",
        sortorder: "asc",
        usepager: false,
        title: false, //'Album'
        useRp: false,
        rp: 10,
        showTableToggleBtn: false,
        width: 'auto', //'auto'
        height: 'auto'
        , onSuccess: function() {} //change row colours here 
        ,onSubmit: function() {}
    });
}
//---------------------------------------------------------------------
// Function called to generate Jquery File Tree
//---------------------------------------------------------------------
function Documents_GenerateJFileTree() {
	var cPath = 'FileSystemBasedConnector.aspx';
	var rootPath = 'D:/';//'D:/SVN Repositories/VM Network/';
	$('#divfileTree').fileTree(
		{
			root: rootPath,
			script: cPath,
			expandSpeed: 1000,
			collapseSpeed: 1000,
			multiFolder: false
		}, function(file) { Documents_BindFilesToFlexiGrid(file); });
  
}
//---------------------------------------------------------------------
// 
//---------------------------------------------------------------------
function Documents_BindFilesToFlexiGrid(path) {
     // declare variable for documents request              	
    var DocumentsRequest = {};
    //assign directory path to Documents request              	
    DocumentsRequest.DirPath = path;
    //Json stringify the Documents request object
    var params = JSON.stringify({ 'documentsRequest': DocumentsRequest });
	//Webservice call to get files under the selected path	
    $.ajax({
        type: "POST",
        url: _absWebRoot + "DMSWebService.asmx/GetFilesFromDirectory",
        contentType: "application/json; charset=utf-8",
        data: params,
        dataType: "json",
        success: Documents_OnGetFilesSuccess,
        error: Documents_OnGetFilesFailure
    });
}
//---------------------------------------------------------------------
// 
//---------------------------------------------------------------------
function Documents_OnGetFilesSuccess(res, ajaxOptions, XMLHttpRequest) {
    // TO DO Bind data to flexigrid
    
    return false;
}
//---------------------------------------------------------------------
// 
//---------------------------------------------------------------------
function Documents_OnGetFilesFailure(xhr, ajaxOptions, thrownError){
    alert(thrownError);
    return false;
}